package com.example.carconsumer.controller.dl.admin;

import com.alibaba.dubbo.config.annotation.Reference;
import com.example.carinterface.service.dl.admin.SettingService;
import com.example.carinterface.utils.ResultJson;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RequestMapping("/admin/setting")
@Api(tags = "设置")
@RestController
public class SettingController {

    @Reference(check = false)
    private SettingService settingService;

    //管理员管理
    @ApiOperation("管理员管理")
    @PostMapping("/findAdmin")
    public ResultJson<List<Map<String, Object>>> findAdmin(@ApiParam("id:管理员id（可不传）") @RequestBody(required = false) Map<String, Object> map) {
        return settingService.findAdmin(map);

    }

    //暂无权限设置(表设计？)
    @ApiOperation("添加账号")
    @PostMapping("/addAdmin")
    public ResultJson<String> addAdmin(@ApiParam("username：账号，" +
            "password：密码，" +
            "state：状态，0冻结，1正常，" +
            "email：邮箱") @RequestBody Map<String, Object> map) {

        String username = map.get("username").toString();
        String password = map.get("password").toString();
        SimpleHash md5 = new SimpleHash("md5", password, username, 32);
        map.put("password", md5.toString());
        return settingService.addAdmin(map);
    }

    @ApiOperation("修改账号")
    @PostMapping("/updateAdmin")
    public ResultJson<String> updateAdmin() {
        return null;
    }


}
